package io.alvin.highlight_spring4.ch2.event;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

/**
 * 事件发布类
 * 1、注入ApplicationContext用来发布事件
 * 2、使用ApplicationContext的publishEvent方法来发布
 *
 * Created by Alvin on 2017/8/1.
 */
@Component
public class DemoPublisher {

    @Autowired
    ApplicationContext applicationContext;

    public void publish(String msg) {
        applicationContext.publishEvent(new DemoEvent(this, msg));
    }
}
